package com.heima.controller;


import com.heima.pojo.dto.TbUserDto;
import com.heima.pojo.vo.PageResponse;
import com.heima.pojo.vo.TbRoleVo;
import com.heima.pojo.vo.TbUserVo;
import com.heima.service.ITbUserService;
import com.heima.service.impl.TbUserServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author AkiRinko
 * @since 2024-06-10
 */
@RestController
@RequestMapping("/api/user-service")
@RequiredArgsConstructor
public class TbUserController {
    private final ITbUserService tbUserService;

    /**
     * 人员搜索
     *
     * @param pageIndex
     * @param pageSize
     * @param userName
     * @return
     */
    @GetMapping("/user/search")
    private PageResponse<TbUserVo> selectUserPage(@RequestParam(value = "pageIndex", required = false, defaultValue = "1") Integer pageIndex,
                                                  @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                                                  @RequestParam(value = "userName", required = false) String userName) {
        return tbUserService.selectUserPage(pageIndex, pageSize, userName);
    }

    /**
     * 角色列表
     */
    @GetMapping("/role")
    private List<TbRoleVo> selectRoleList() {
        return tbUserService.selectRoleList();
    }

    /**
     * 新增人员
     *
     * @param dto
     */
    @PostMapping("/user")
    private void insertUser(@RequestBody TbUserDto dto) {
        tbUserService.insertUser(dto);
    }

    /**
     * 修改人员
     *
     * @param userId
     * @param dto
     */
    @PutMapping("/user/{userId}")
    private void updateUser(@PathVariable Integer userId,
                            @RequestBody TbUserDto dto) {
        tbUserService.updateUser(userId, dto);
    }

    /**
     * 删除人员
     *
     * @param userId
     */
    @DeleteMapping("/user/{userId}")
    private void deleteUser(@PathVariable Integer userId) {
        tbUserService.deleteUser(userId);
    }



}
